package com.zhengwl.study.sort;

public class BinarySearch {

	private int[] arrays;
	public BinarySearch(int[] items){
		this.arrays=items;
	}
	
	public int search(int value){
		int left=0;
		int right=arrays.length-1;		
		while (left<=right) {
			int mid=(left+right)/2;
			if(arrays[mid]==value){
				return mid;
			}else if(arrays[mid]<value){
				left=mid+1;
			}else {
				right=mid-1;
			}
		}	
		return -1;
	}
	
}
